import request from '@/utils/request'
import dateApi from '@/utils/date'

export default {
    confirmOrder(orderId){
        const req = request({
            method: 'put',
            url: '/dgut/confirmOrder',
            params: {
                codes:sessionStorage.getItem("codes"),
                orderId,
                orderStatus: "已完结"
            }
        })
        return req;
    },
    getAllOrderByStatus(openid,status){
        const req = request({
            method: 'get',
            url: '/dgut/getAllOrderByStatus',
            params: {
                openid,
                orderStatus: status
            }
        })
        return req;
    },
    search(searchMap) {
        if (searchMap.orderId != "") {
            const req = request({
                method: 'get',
                url: '/dgut/getAllOrderByOrderId',
                params: {
                    orderId:searchMap.orderId,
                    orderStatus:searchMap.orderStatus
                }
            })
            return req;
        } else if (searchMap.orderOpenid != "") {
            return this.getAllOrderByStatus(searchMap.orderOpenid,searchMap.orderStatus);
        } else if (searchMap.orderPhone != "") {
            const req = request({
                method: 'get',
                url: '/dgut/getAllOrderByPhone',
                params: {
                    orderPhone:searchMap.orderPhone,
                    orderStatus:searchMap.orderStatus
                }
            })
            return req;
        }  else if (searchMap.value2 != "") {
            var date1 = new Date(searchMap.value2[0]);
            var date2 = new Date(searchMap.value2[1]);
            var begindate = dateApi.getDate(date1);
            var enddate = dateApi.getDate(date2);
            const req = request({
                method: 'get',
                url: '/dgut/getAllOrderByTime',
                params: {
                    begindate, enddate,
                    orderStatus:searchMap.orderStatus
                },
            })
            return req;
        } else{
            return this.getAllOrderByStatus("0",searchMap.orderStatus)
        }
    }
}